package com.kfm.pm;

public class Demo01 {

    public static void test01(String msg) throws MXBCException {
        if (msg.contains("芋圆")) {
            throw new MXBCException("没有芋圆了");
        }
        System.out.println("做好了，您慢用！");
    }

    public static void test02(String msg) throws Exception {
        try {
            test01(msg);
        } catch (MXBCException e) {
//            System.out.println(e.getMessage());
            throw new Exception("做不了", e);
        }
    }

    public static void main(String[] args) {
        try {
            test02("我要一杯芋圆葡萄");
        } catch (Exception e) {
            System.out.println(e.getMessage()); // 做不了
            System.out.println(e.getCause().getMessage()); // 没有芋圆
            e.printStackTrace();
        }
    }
}

class MXBCException extends Exception {
    public MXBCException (String message) {
        // message 内容最终赋值给 Throwable对象的 detailMessage 成员变量
        // getMessage() 方法获取这个信息
        super(message);
    }
}
